<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use kartik\file\FileInput;

/* @var $this yii\web\View */
/* @var $model backend\modules\wxad\models\WxAd */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="wx-ad-form">

    <?php $form = ActiveForm::begin(); ?>

    <div class="FormPage01">

        <?= $form->field($model, 'ad_cat_id')->dropDownList(\yii\helpers\ArrayHelper::map(\backend\modules\wxad\models\WxAdCat::find()->select(['rec_id','ad_cat_name'])->asArray()->all(),'rec_id', 'ad_cat_name'));?>


        <?= $form->field($model, 'ad_name')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'ad_link')->textInput(['maxlength' => true]) ?>
    </div>

    <div class="FormPage02" style="display: none">

        <?php
        $initialPreview =  array($model->ad_images);
        $initialPreviewConfig = array($model->ad_images);

            $initialPreview = "<img width='100%' height='100%' src='" .  '../' .$model->ad_images. "' class='file-preview-image'>";
            $initialPreviewConfig = [
                'caption' => $model->ad_images,
                'url' => Url::to(['/wxad/wxad/deleteimage', 'id' => $model->rec_id]),
            ];

        ?>
        <?=$form->field($model, 'ad_images')->label(Yii::t('catalog','Image(请先上传图片)'))->widget(FileInput::classname(), [
            'language' => 'zh',
            'options' => [ 'accept' => 'image/*', 'multiple'=>false],
            'pluginOptions' => [
                'initialPreview'=>$initialPreview,
                'initialPreviewConfig'=>$initialPreviewConfig,
                'overwriteInitial'=>true,
                'showCaption'=>true,
                'showCancel'=>true,
                'showBrowse'=>true,
                'uploadUrl' => Url::to(['/wxad/wxad/adupload']),
                'uploadExtraData' => [
                    'rec_id' => $model->rec_id,
                    'ad_name' => $model->ad_name,
                    'position' => 5//TODO:  js
                ],
                'dropZoneEnabled'=>true,
                'maxFileCount' => 10,
                'allowedFileExtensions'=>['jpg','gif','png']
            ]
        ]);?>



    </div>


    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
